#include "defaultShader.h"

DefaultShader::DefaultShader() {}
DefaultShader::~DefaultShader() {}

VsOutput DefaultShader::vertexShader(
	const std::map<uint32_t, BindingDescription>& bindingMap,
	const std::map<uint32_t, BufferObject*>& bufferMap,
	const uint32_t& index           
) {
	VsOutput output;                                        //bindingMap对应的key   //ebo存的index
	math::vec4f position = getVector(bindingMap, bufferMap, 0, index);
	position[3] = 1.0f;
	math::vec4f color = getVector(bindingMap, bufferMap, 1, index);
	math::vec2f uv = {getVector(bindingMap, bufferMap, 2, index)[0],getVector(bindingMap, bufferMap, 2, index)[1]};
    auto result = math::from_expr(mProjectionMatrix * mViewMatrix * mModelMatrix);
	output.mPosition = result* position;
	output.mColor = color;
	output.mUV = uv;
	return output;
}

void DefaultShader::fragmentShader(const VsOutput& input, FsOutput& output) {
	output.mPixelPos[0] = static_cast<int>(input.mPosition[0]);
	output.mPixelPos[1] = static_cast<int>(input.mPosition[1]);
	output.mDepth = input.mPosition[2];
	output.mColor = vectorToRGBA(input.mColor);
}
